package cn.jb698.codec.msm.zcodec.demo.msm;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONObject;

import cn.jb698.codec.msm.generator.v5base.QueryOrmCreateCodeFilesImpl;
import cn.jb698.codec.msm.generator.v5base.QueryOrmCreateJsonImpl;
import cn.jb698.codec.msm.generator.v5base.beans.QueryOrmBean;
import cn.jb698.codec.msm.generator.v5base.beans.QueryOrmConfigBean;
import cn.jb698.codec.msm.generator.v5base.beans.QueryOrmMapperJsBean;
import cn.jb698.codec.msm.zcodec.demo.CodecPropertiesUtils;

/**
 * 
 * @author Administrator(LiuJianbin)
 * @date 2019-04-02
 *
 */
public class ZCodecMysqlQuery {
	
	
	public static void main(String[] args) throws Exception {

		QueryOrmConfigBean confBean = init_proj_bsorm();
		QueryOrmCreateJsonImpl createJsonImpl = new QueryOrmCreateJsonImpl();
		QueryOrmCreateCodeFilesImpl createCodeImpl = new QueryOrmCreateCodeFilesImpl();
		List<QueryOrmMapperJsBean> createBusiOrmJsBeans = createJsonImpl.createQueryOrmJsBeans(confBean);
		for(QueryOrmMapperJsBean tmpJsBean : createBusiOrmJsBeans ){
			QueryOrmBean busiOrmJsBean = JSONObject.parseObject(JSONObject.toJSONString(tmpJsBean), QueryOrmBean.class); 
			createCodeImpl.createAndOutputCodeFiles(confBean, busiOrmJsBean );
		}
	}

	/**
	 * 初始化库.
	 * @throws IOException 
	 */
	public static QueryOrmConfigBean init_proj_bsorm() throws IOException{
		{
			
	        String default_driverClassName = CodecPropertiesUtils.getPropVal("spring.datasource_mysql.driver-class-name"); 
	        String default_connectUrl = CodecPropertiesUtils.getPropVal("spring.datasource_mysql.url");
	        String default_userName = CodecPropertiesUtils.getPropVal("spring.datasource_mysql.username");
	        String default_password = CodecPropertiesUtils.getPropVal("spring.datasource_mysql.password");

	        String basePackageName = "cn.jb698.codec.demo.bcrud.dbmysql";
	        String xmlMapperPackage = "mybatis.codec.dbmysql.mapper";

	        String tgtProjDir="D:/Develope/workspace/codec/codec_msm_demo"; // 目标项目路径. 对比路径
	        String jsonFile_outDir = tgtProjDir + "/table_jsons/";
	        String codeOutDir = tgtProjDir + "/src/main/java/" ;
	        String resOutDir = tgtProjDir + "/src/main/resources/" ;
	        String pageOutDir = tgtProjDir + "/src/main/webapp/WEB-INF/jsp/temp_aceadmin/bcrud/" ;
	        
	        List<String> xmlFileResPaths = new ArrayList<>();
//	        xmlFileResPaths.add("/loanplatform/UserQuerys.xml");
	        //执行需要联表查的xml  下面需要更改名字
	        xmlFileResPaths.add("/codec/bsorm/mysql/MqDemoDataInfQuerys.xml");
			QueryOrmConfigBean confBean = new QueryOrmConfigBean();
			confBean.setDbDriverClassName(default_driverClassName);
			confBean.setDbConnectionUrl(default_connectUrl);
			confBean.setDbUserName(default_userName);
			confBean.setDbPassword(default_password);
			confBean.setBasePackageName(basePackageName);
			confBean.setMapperXmlPackageName(xmlMapperPackage);

			confBean.setJavaCodeRootDir(codeOutDir);
			confBean.setResCodeRootDir(resOutDir);
			confBean.setPageCodeRootDir(pageOutDir); 
			confBean.setJsonFileOutDir(jsonFile_outDir);
			confBean.setXmlFileResources(xmlFileResPaths);
			return confBean ;
		}
	}
	
}
